package com.wn.netty.nio;

import java.util.concurrent.atomic.LongAdder;

/**
 * @FileName: BufferTest
 * @Description: TODO
 * @Author: MaWenHao
 * @Created: 2020/7/24 - 10:11
 * @Version: V1.0
 * @Company: 东方微银科技（北京）有限公司
 */
public class BufferTest {

    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();
        System.out.println(longAdder.longValue());
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();
        System.out.println(longAdder.longValue());
        longAdder.reset();
        System.out.println(longAdder.longValue());

    }

    // public static void main(String[] args) {
    //     try (final RandomAccessFile accessFile = new RandomAccessFile("D:\\\\example\\\\test1.txt", "rw");
    //          final FileChannel channel = accessFile.getChannel();
    //     ) {
    //         final MappedByteBuffer mappedByteBuffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 7);
    //         mappedByteBuffer.put( (byte) 'A');
    //         mappedByteBuffer.put( (byte) 'B');
    //         mappedByteBuffer.put( (byte) 'C');
    //
    //         mappedByteBuffer.flip();
    //         final byte b = mappedByteBuffer.get();
    //         System.out.println((char) b);
    //     } catch (IOException e) {
    //         e.printStackTrace();
    //     }
    //
    // }

    // public static void main(String[] args) {
    //     try (FileInputStream input = new FileInputStream("D:\\example\\test1.txt");
    //          FileChannel inputChannel = input.getChannel();
    //          FileOutputStream output = new FileOutputStream("D:\\example\\test2.txt");
    //          final FileChannel outputChannel = output.getChannel()
    //     ) {
    //         // inputChannel.transferTo(0, inputChannel.size(), outputChannel);
    //         outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
    //     } catch (Exception e) {
    //         e.printStackTrace();
    //     }
    // }

    // public static void main(String[] args) {
    //     try (FileInputStream input = new FileInputStream("D:\\example\\test1.txt");
    //          FileChannel inputChannel = input.getChannel();
    //          FileOutputStream output = new FileOutputStream("D:\\example\\test2.txt");
    //          final FileChannel outputChannel = output.getChannel()
    //     ) {
    //         ByteBuffer buffer = ByteBuffer.allocate(1024);
    //         int index;
    //         while ((index = inputChannel.read(buffer)) != -1) {
    //             buffer.flip();
    //             outputChannel.write(buffer);
    //             buffer.clear();
    //         }
    //     } catch (Exception e) {
    //         e.printStackTrace();
    //     }
    // }

    // public static void main(String[] args) {
    //     try (FileInputStream input = new FileInputStream("D:\\example\\test1.txt");
    //          FileChannel channel = input.getChannel();
    //     ) {
    //         ByteBuffer bf = ByteBuffer.allocate(1024);
    //         channel.read(bf);
    //
    //         byte[] array = bf.array();
    //         System.out.println(new String(bf.array()));
    //
    //
    //     } catch (IOException e) {
    //         e.printStackTrace();
    //     }
    // }

    // public static void main(String[] args) {
    //     try (FileOutputStream output = new FileOutputStream("D:\\example\\test1.txt");
    //          FileChannel channel = output.getChannel();
    //     ) {
    //         ByteBuffer bf = ByteBuffer.allocate(1024);
    //         bf.put("hello world".getBytes("UTF-8"));
    //
    //         bf.flip();
    //         channel.write(bf);
    //
    //     } catch (IOException e) {
    //         e.printStackTrace();
    //     }
    // }
}
